
// 接口方法
import request from '@/utils/request'
export const getChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'// 获取频道列表
  })
}

// 登录功能接口
export const LoginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations', // 登录接口
    method: 'POST',
    data: {
      mobile: mobile,
      code: code
    }
  })
}

// 获取已选频道的列表
export const getChannelAPI = () => request({
  url: '/v1_0/user/channels'

})

// 设置用户的频道（重置式）

export const setUserChannelAPI = (channelsArr) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels: channelsArr// 数组转对象发给后台,转成json字符串发给后台
  }

})

// 删除指定用户频道(点X删除)
export const delChannelAPI = (channelId) => request({
  url: `/v1_0/user/channels/${channelId}`,
  method: 'DELETE'
})

// 获取每一项文章列表
export const getArticlesItemAPI = ({ channel_id, timestamp = new Date() }) => request({
  url: '/v1_0/articles',

  params: {
    channel_id,
    timestamp

  }

})

// 对文章不喜欢
export const dislikeArticleAPI = (artId) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',

  data: {
    target: artId
  }

})

// 举报文章
export const jubaoArticleAPI = ({ target, type }) => request({
  url: '/v1_0/article/reports',
  method: 'POST',

  data: {
    target: target,
    type: type,
    remark: '就是举报文章'
  }

})

// 获取联想建议（自动补全）
export const suggestionAPI = (keyWords) => request({
  url: '/v1_0/suggestion',
  params: {
    q: keyWords
  }
})

// 获取搜索结果
export const searchResultAPI = ({ page = 1, per_page = 10, q }) => request({
  url: '/v1_0/search',
  params: {
    page: page,
    per_page: per_page,
    q: q
  }
})

// 获取新闻详情
export const getArticlesDetailAPI = (artId) => request({
  url: `/v1_0/articles/${artId}`

})

// 关注
export const followedAPI = (target) => request({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: {
    target
  }

})

// 不关注
export const unfollowedAPI = (target) => request({
  url: `/v1_0/user/followings/${target}`,
  method: 'DELETE'

})

// 喜欢
export const likeAPI = (target) => request({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target
  }

})
// 不喜欢
export const unlikeAPI = (target) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target
  }

})

// 获取评论或评论回复
export const getCommentAPI = ({ type = 'a', artId, offset = null, limit = 10 }) => request({
  url: '/v1_0/comments',
  params: {
    type: 'a',
    source: artId,
    offset: offset,
    limit: limit
  }
})

// 对评论或评论回复点赞
export const likeCommitAPI = ({ com_id }) => request({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: {
    target: com_id
  }
})

// 对文章或者评论进行评论(特殊)
// export const sendCommentAPI = ({}) =>request ({
//   // const obj = {
//   //   target: target,
//   //   content:content
//   // }
// })
export const sendCommentAPI = ({ target, content }) => request({

  url: '/v1_0/comments',
  method: 'POST',
  data: {
    target: target, // 文章id或者是评论ID
    content: content
  }
})

// 取消对评论或评论回复点赞
export const unlikeCommitAPI = ({ com_id }) => request({
  url: `/v1_0/comment/likings/${com_id}`,
  method: 'DELETE'

})

// 获取用户自己信息
export const userMessageAPI = () => request({
  url: '/v1_0/user'

})
// 获取用户个人资料
export const getUserMessaggeAPI = () => request({
  url: '/v1_0/user/profile'

})

// 编辑用户照片资料（头像、身份证照片）
export const editUserMessageAPI = (fd) => request({
  url: '/v1_0/user/photo',
  method: 'PATCH', // 局部更新,put一半是全局更新
  data: fd//  // 如果你的请求体内容是表单对象,
  //  浏览器会自动携带请求头Content- Type为multipart / form - data

})

// 编辑用户个人资料
export const updateProfileAPI = ({ userName = null, birthday = null }) => request({
  url: '/v1_0/user/profile',
  method: 'PATCH', // 局部更新,put一半是全局更新
  data: {
    name: userName,
    birthday: birthday
  }
})

// 刷新用户token
export const refreshTokenAPI = () => request({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('refresh_token')// 本地地址拿
  }
})
